using System.Collections;
using System.Collections.Generic;
using Commons.Models.Definitions;
using Commons.Models.Settings.Dtos.Scores;
using Commons.Models.Settings.Mappers.Scores;

namespace Commons.Models.Settings.Parsers
{
	public class HighScoreSettingsParser : BaseSettingsParser<HighScoreConfigDto>
	{
		public HighScoreSettingsParser()
			: base("Data/shared/highscore-config")
		{
		}

		public override IEnumerator Parse(ParserContext context, ISettingsModel settingsModel)
		{
			HighScoreConfigDto config = Deserialize();
			yield return null;

			TotalObjects = config.HighScores.Count;

			List<HighScoreDefinition> highScores = new List<HighScoreDefinition>();
			HighScoreDefinitionMapper mapper = new HighScoreDefinitionMapper();
			foreach (HighScoreDefinitionDto highScore in config.HighScores)
			{
				highScores.Add(mapper.Map(highScore));

				NumObjects++;

				yield return null;
			}

			settingsModel.AddSetting(new HighScoreSettings(highScores));
		}
	}
}

